package org.xg.study.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @author CMG
 * @version 1.0
 * @className DispatcherServlet
 * @description
 * @date 2021/9/23 22:01
 **/
@WebServlet("/dispatcher")
public class DispatcherServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("text/html;charset=UTF-8");
        PrintWriter printWriter = resp.getWriter();
        printWriter.write("<h1>这是转发前在响应信息的内容！</h1>");
        req.setAttribute("webName","C语言中文网");
        req.setAttribute("url","www.biancheng.net");
        req.setAttribute("welcome","欢迎你");
        //转发
        req.getRequestDispatcher("/DoServlet").forward(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
